package cn.edu.imust.loginregisterdemo.splsh;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import cn.edu.imust.loginregisterdemo.R;
import cn.edu.imust.loginregisterdemo.home.view.MainActivity;
import cn.edu.imust.loginregisterdemo.login.view.LoginActivity;

public class SplashActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        init();

    }

    private void init() {
        Bmob.initialize(this, "33452dfaa0b4f1b9b1a5ea2c1818d5f4");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                if (BmobUser.isLogin()) {
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    finish();
                }else {
                    startLogin();
                }

            }
        }, 3000);
    }



    /**
     * 跳转到登录界面
     */
    private void startLogin() {
        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();                   //销毁闪屏界面
    }

}
